package com.lc.demo.service.impl;


import com.lc.demo.bean.Admin;
import com.lc.demo.bean.Score;
import com.lc.demo.bean.Subject;
import com.lc.demo.mapper.AdminMapper;
import com.lc.demo.mapper.ScoreMapper;
import com.lc.demo.service.ScoreService;
import com.lc.demo.service.SubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScoreServiceImpl implements ScoreService {


    @Autowired
    public ScoreMapper scoreMapper;

    @Autowired
    AdminMapper adminMapper;


    @Override
    public void review(Score score) {
        scoreMapper.review(score);
    }

    @Override
    public List<Score> selectScoreListByUsername(String username) {
        return scoreMapper.selectScoreListByUsernameAndStatus2(username);
    }

    @Override
    public List<Score> findScoreList(Score score) {

        return scoreMapper.findScoreList(score);
    }

    @Override
    public void adminReview(Score score) {

        if (score.getStatus() == 1) {

        }

        scoreMapper.adminReview(score);
    }

    @Override
    public List<Score> findScoreListTeacher(Integer  teacherId) {
        return scoreMapper.findScoreListTeacher(teacherId);
    }

    @Autowired
    SubjectService subjectService;

    @Override
    public void addScore(Score score) {
        //根据课程名 查询出课程ID
      /*  Subject subject = subjectService.selectSubjectByName(score.getSubname());
        score.setSubId(subject.getId());*/
     Subject subject=   subjectService.subJectById(score.getSubId());
     score.setSubname(subject.getName());
        scoreMapper.addScore(score);
    }

    @Override
    public void delScoreById(Score score) {
        scoreMapper.delScoreById(score);
    }

    @Override
    public Score getScoreById(Score score) {
        return scoreMapper.getScoreById(score);
    }

    @Override
    public void teacherReview(Score score) {
        score.setStatus(0);
        scoreMapper.teacherReview(score);

    }

    @Override
    public void updateScore(Score score) {
        scoreMapper.updateScore(score);
    }

    @Override
    public List<Score> findScoreListByUsername(Score score, String username) {

        //根据当前用户 查询出教务员  然后查询改院系下所有成绩
       Admin admin=  adminMapper.findByUsername(username);
       //院系Id
        Integer departmentid = admin.getDepartmentid();
        return   scoreMapper.findScoreListBydepartmentid(departmentid);
    }
}
